<style>
    :root {
        --color1: #009C5E;
    }

    xm-select {
        box-sizing: border-box;
    }

    .mainCabinetAuthorityForm .open-details-box {
        height: calc(100% - 100px);
        overflow: auto;
    }

    form[lay-filter="addPermissionGroupMembersForm"] label {
        padding: 9px;
        width: 90px;
    }

    form[lay-filter="addPermissionsGroupForm"] label {
        padding: 9px;
        width: 155px;
    }

    form[lay-filter="addPermissionsGroupForm"] input {
        width: 280px;
    }

    form[lay-filter="addPermissionsGroupForm"] .open-details-box .layui-row .layui-inline {
        height: auto;
        transition: all 300ms;
    }

    form[lay-filter="addPermissionsGroupForm"] .layui-radio-disbaled > i {
        color: #1BA70E !important;
    }


    .mainCabinetAuthorityForm label {
        width: auto;
        padding: 9px 0;
    }


    .colorBlack {
        padding-right: 15px;
        color: var(--color1);
        font-weight: 600;
    }

    .colorBlack1 {
        padding-right: 15px;
    }

    .addPermissionGroupMembersDetail {
        display: none;
    }

    .receiveNewExcess {
        display: none;
    }
</style>


<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">输入权限组名称：</label>
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input" placeholder="请输入权限组名称" name="name">
                                    </div>
                                </div>
                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="mainCabinetAuthorityFormSearch" lay-submit layui-form-keyDownSearch="true">查询</button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="lay-btn-rows">
                    <div class="lay-btn-box">
                        <div class="lay-btn-lt">
                            <button id="addPermissionsGroupBtn" class="layui-btn icon-btn color-reseda">添加</button>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 表格 -->
            <table class="layui-table" id="mainCabinetAuthorityTable" lay-filter="mainCabinetAuthorityTable"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="mainCabinetAuthorityFormTableBar">
    <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="details">详情</a>
    <a class="layui-btn layui-btn-xs" lay-event="modify">修改</a>
    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="member">成员管理</a>
    {{# if(d.status =='0'){ }}
    <!--    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="disable">禁用</a>-->
    {{# }else{ }}
    <!--    <a class="layui-btn layui-btn-xs" lay-event="enable">启用</a>-->
    {{# } }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
</script>

<script type="text/html" id="addPermissionsGroupForm">
    <form lay-filter="addPermissionsGroupForm" class="layui-form model-form"
          style="padding: 5px 10px 0;height: calc(100% - 5px);overflow: hidden;">
        <div class="open-details-box"
             style="height: calc(100% - 65px); overflow-y: scroll; overflow-x: hidden; padding-top: 15px;">
            <input name="id" type="hidden" class="layui-input"/>
            <div class="layui-row layui-col-space20">
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">权限组名称</label>
                    <div class="layui-input-inline">
                        <input name="name" type="text" class="layui-input" placeholder="权限组名称"
                               lay-reqText="请输入权限组名称" lay-verify="required" autocomplete="off"/>
                    </div>
                </div>
                <div class="layui-inline layui-col-md6" style="display: none">
                    <label class="layui-form-label">是否启用</label>
                    <div class="layui-input-block">
                        <input type="checkbox" checked="" name="status" lay-skin="switch" lay-filter="switchTest"
                               lay-text="启用|不启用" disabled readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">领新授信类型</label>
                    <div class="layui-input-inline">
                        <input type="radio" name="creditType" value="money" title="金额" checked=""
                               lay-filter="creditType">
                        <input type="radio" name="creditType" value="quantity" title="数量" lay-filter="creditType">
                    </div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">授信方式</label>
                    <div class="layui-input-inline">
                        <select name="creditWay" lay-verify="required" lay-reqText="请选择授信方式" lay-filter="creditWay">
                            <option value="">请选择授信方式</option>
                            <option value="share">组员共享领用金额</option>
                            <option value="independent">组员独立授信领用金额</option>
                            <option value="unlimited">不限制领用金额</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline layui-col-md6" id="creditAmountQuantityBox">
                    <label class="layui-form-label" id="creditAmountQuantityLabel">标准授信额度</label>
                    <div class="layui-input-inline">
                        <input type="text" name="creditAmount" class="layui-input" placeholder="请输入标准授信额度">
                        <input type="text" name="creditQuantity" class="layui-input" placeholder="请输入标准授信数量"
                               style="display: none">
                    </div>
                </div>

                <div class="layui-inline layui-col-md6" id="practicalLineOfCreditBox" style="display: none">
                    <label class="layui-form-label">实际授信金额</label>
                    <div class="layui-input-inline">
                        <input type="text" name="practicalLineOfCredit" class="layui-input" readonly disabled>
                    </div>
                </div>
                <div class="layui-inline layui-col-md6" id="practicalCreditQuantityBox" style="display: none">
                    <label class="layui-form-label">实际授信数量</label>
                    <div class="layui-input-inline">
                        <input type="text" name="practicalCreditQuantity" class="layui-input" readonly disabled>
                    </div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">额度评估周期</label>
                    <div class="layui-input-inline">
                        <select name="lineEvaluatePeriod" lay-verify="required" lay-reqText="请选择额度评估周期">
                            <option value="">请选择额度评估周期</option>
                            <option value="day">每天</option>
                            <option value="week">每周</option>
                            <option value="month">每月</option>
                            <option value="quarter">每季度</option>
                            <option value="year">每年</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline layui-col-md6" id="moneyThresholdBox">
                    <label class="layui-form-label">未归还金额阈值</label>
                    <div class="layui-input-inline">
                        <input name="moneyThreshold" type="text" class="layui-input" placeholder="请输入金额"
                               lay-verify="required"
                               onkeyup="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1')"/>
                    </div>
                </div>
                <div class="layui-inline layui-col-md6" id="quantityThresholdBox" style="display: none">
                    <label class="layui-form-label">未归还数量阈值</label>
                    <div class="layui-input-inline">
                        <input name="quantityThreshold" type="text" class="layui-input" placeholder="请输入数量"
                               onkeyup="this.value = this.value.replace(/^0+(?=\d)|[^\d]/g, '')"/>
                    </div>
                </div>
                <div class="layui-inline layui-col-md6" id="authotizedStatusBox">
                    <label class="layui-form-label" id="authotizedStatusLabel">单物料领用金额</label>
                    <div class="layui-input-inline">
                        <input type="radio" name="authotizedStatus" value="0" title="限制" checked=""
                               lay-filter="authotizedStatus">
                        <input type="radio" name="authotizedStatus" value="1" title="不限制" lay-filter="authotizedStatus">
                    </div>
                </div>
                <div class="layui-inline layui-col-md6" id="lineOfCreditBox">
                    <label class="layui-form-label">单物料金额限制阈值</label>
                    <div class="layui-input-inline">
                        <input name="lineOfCredit" type="text" class="layui-input" placeholder="单物料金额限制阈值"
                               id="lineOfCredit"
                               onkeyup="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1')"
                               lay-verify="required"/>
                    </div>
                </div>
                <div class="layui-inline layui-col-md6" style="display: none;" id="authorizedQuantityBox">
                    <label class="layui-form-label">单物料数量限制阈值</label>
                    <div class="layui-input-inline">
                        <input name="authorizedQuantity" type="text" class="layui-input" placeholder="请输入单物料数量限制阈值"
                               id="authorizedQuantity"
                               onkeyup="this.value = this.value.replace(/^0+(?=\d)|[^\d]/g, '')"/>
                    </div>
                </div>

                <div class="layui-inline layui-col-md6" id="astrictMaterialBox">
                    <label class="layui-form-label">管控物资范围</label>
                    <div class="layui-input-inline">
                        <select name="astrictMaterial" lay-verify="required" lay-reqText="请选择是否限制物料"
                                lay-filter="astrictMaterial">
                            <option value="astrict">指定物料</option>
                            <option value="noAstrict">所有物料</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline layui-col-md6" id="restrictWayBox">
                    <label class="layui-form-label">添加方式</label>
                    <div class="layui-input-inline">
                        <input type="radio" name="restrictWay" value="category" title="按分类限制" checked=""
                               lay-filter="materiel">
                        <input type="radio" name="restrictWay" value="materiel" title="按物料限制" lay-filter="materiel">
                    </div>
                </div>
                <div class="layui-inline layui-col-md6" id="materialIdBox">
                    <label class="layui-form-label">管控物资分类</label>
                    <input name="materialId" type="hidden" class="layui-input"/>
                    <div class="layui-input-inline" id="materialId" style="width: 280px;"></div>
                </div>

                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">选择主柜</label>
                    <div class="layui-input-inline" style="width: 280px;">
                        <input type="hidden" name="cabinetId" class="layui-input">
                        <input type="hidden" name="cabinetCode" class="layui-input">
                        <div id="cabinetBox"></div>
                    </div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-inline">
                        <input name="remark" type="text" class="layui-input" placeholder="备注"/>
                    </div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">领料超额审核</label>
                    <div class="layui-input-block">
                        <input type="radio" name="excessStatus" value="0" title="开启" lay-filter="isExcessStatus">
                        <input type="radio" name="excessStatus" value="1" title="关闭" checked
                               lay-filter="isExcessStatus">
                    </div>
                </div>
                <div class="layui-inline layui-col-md6 receiveNewExcess receiveNewExcessRequired">
                    <label class="layui-form-label">超额审核人</label>
                    <div class="layui-input-inline">
                        <select name="excessAuditor" lay-search></select>
                    </div>
                </div>
                <div class="layui-inline layui-col-md6 receiveNewExcess receiveNewExcessRequired">
                    <label class="layui-form-label">超额复审额度阈值</label>
                    <div class="layui-input-inline">
                        <input name="recheckAmount" type="text" class="layui-input" placeholder="超额复审额度阈值"/>
                    </div>
                    <!--                    <div class="layui-inline layui-word-aux" style="vertical-align: baseline;">单元: 元</div>-->
                </div>
                <div class="layui-inline layui-col-md6 receiveNewExcess receiveNewExcessRequired">
                    <label class="layui-form-label">超额复审审核人</label>
                    <div class="layui-input-inline">
                        <select name="recheckAmountAuditor" lay-search lay-filter="recheckAmountAuditorFn"></select>
                    </div>
                </div>
                <div class="layui-inline layui-col-md6 receiveNewExcess">
                    <label class="layui-form-label">超额复审审核人邮箱</label>
                    <div class="layui-input-inline">
                        <input name="email" type="text" class="layui-input" placeholder="超额复审审核人邮箱" readonly/>
                    </div>
                </div>
            </div>
            <div class="layui-form-item" style="display: flex;align-items: center;justify-content: space-between;">
                <div class="color-title" style="flex: 1">SKU限制数</div>
                <button class="layui-btn color-green" type="button" id="addPermissionsGroupAdd" style="display: none">
                    添加限制物料
                </button>
            </div>
            <div id="addPermissionsGroupFormTableBox">
                <table class="layui-table" id="addPermissionsGroupFormTable"
                       lay-filter="addPermissionsGroupFormTable"></table>
            </div>
        </div>

        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="addPermissionsGroupFormSubmit" lay-submit type="button">保存</button>
        </div>
    </form>
</script>

<!--权限组操作-->
<!--addPermissionsGroupFormTableBar-->
<script type="text/html" id="addPermissionsGroupFormTableBar">
    {{# if(d.colsIsShow){ }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
    {{# }else{ }}
    {{# } }}
</script>

<!--添加限制物料-->
<!--addRestrictedMaterials-->
<script type="text/html" id="addRestrictedMaterialsTemplate">
    <div lay-filter="addRestrictedMaterialsForm" class="layui-form model-form"
         style="padding: 15px 10px 0;height: calc(100% - 15px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 65px); overflow-y: auto;">
            <div class="layui-row">
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">物料名称</label>
                    <div class="layui-input-inline">
                        <input name="skuName" type="text" class="layui-input" placeholder="请输入物料名称" autocomplete="off"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">物料编号</label>
                    <div class="layui-input-inline">
                        <input name="skuCode" type="text" class="layui-input" placeholder="请输入物料编号" autocomplete="off"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">规格码</label>
                    <div class="layui-input-inline">
                        <input name="oldSpecCode" type="text" class="layui-input" placeholder="请输入规格码"
                               autocomplete="off"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">品牌</label>
                    <div class="layui-input-inline">
                        <input name="productBrandName" type="text" class="layui-input" placeholder="请输入品牌"
                               autocomplete="off"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn icon-btn color-green"
                            lay-filter="addRestrictedMaterialsFormSearch" lay-submit layui-form-keyDownSearch="true"><i
                            class="layui-icon layui-icon-search"></i>查询
                    </button>
                </div>
            </div>
            <div class="layui-form-item">
                <table class="layui-table" id="addRestrictedMaterialsFormTable"
                       lay-filter="addRestrictedMaterialsFormTable"></table>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="addRestrictedMaterialsFormSubmit" lay-submit
                    id="addRestrictedMaterialsFormSubmit">保存
            </button>
        </div>
    </div>
</script>

<!--成员管理-->
<!--memberForm-->
<script type="text/html" id="memberForm">
    <div lay-filter="memberForm" class="layui-form model-form"
         style="padding: 20px 20px 0;height: calc(100% - 20px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 65px); overflow-y: auto;">
            <div class="layui-row">
                <label class="layui-form-label w-auto">成员姓名</label>
                <div class="layui-input-inline">
                    <input name="userName" type="text" class="layui-input" placeholder="输入成员姓名"/>
                </div>
                <div class="layui-inline" style="padding-left: 10px;">
                    <button type="button" class="layui-btn icon-btn color-green"
                            lay-filter="memberFormSearch" lay-submit><i class="layui-icon layui-icon-search"
                                                                        layui-form-keyDownSearch="true"></i>查询
                    </button>
                    <button type="button" class="layui-btn icon-btn" id="addMembersBtn">添加成员</button>
                    <button type="button" class="layui-btn icon-btn" id="memberFormExport">导出数据</button>
                    <button type="button" class="layui-btn icon-btn layui-btn-danger" id="memberFormBatchDeletion">批量删除
                    </button>
                </div>
            </div>
            <div class="layui-form-item">
                <table class="layui-table" id="memberFormTable" lay-filter="memberFormTable"></table>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </div>
</script>


<!--成员管理操作列-->
<!--memberFormBar-->
<script type="text/html" id="memberFormTableBar">
    <a class="layui-btn layui-btn-xs" lay-event="details">详情</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
</script>

<!--添加权限组成员-->
<!--addPermissionGroupMembers-->
<script type="text/html" id="addPermissionGroupMembers">
    <div lay-filter="addPermissionGroupMembersForm" class="layui-form model-form"
         style="padding: 5px 20px 0;height: calc(100% - 5px);overflow: hidden;" id="addPermissionGroupMembersForm">
        <div class="open-details-box"
             style="height: calc(100% - 65px); overflow-y: auto; overflow-x: hidden; padding-top: 15px;">
            <div class="layui-form-item">
                <label class="layui-form-label">权限组名称</label>
                <div class="layui-input-block">
                    <input name="name" type="text" class="layui-input" style="border-color: transparent" disabled/>
                </div>
            </div>
            <div class="layui-form-item" id="addPermissionGroupMembersFormLineOfCreditBox" style="display: none">
                <label class="layui-form-label">授权额度</label>
                <div class="layui-input-block">
                    <input name="lineOfCredit" type="text" class="layui-input" style="border-color: transparent"
                           disabled/>
                </div>
            </div>
            <div class="layui-form-item" id="addPermissionGroupMembersFormAuthorizedQuantityBox" style="display: none">
                <label class="layui-form-label">授权数量</label>
                <div class="layui-input-block">
                    <input name="authorizedQuantity" type="text" class="layui-input" style="border-color: transparent"
                           disabled/>
                </div>
            </div>
            <div class="layui-form-item" id="materialId1Box" style="display: none">
                <label class="layui-form-label">可领物资分类</label>
                <input name="materialId" type="hidden"/>
                <div class="layui-input-block" id="materialId1"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">选择人员</label>
                <div class="layui-input-block" id="userIdBox"></div>
                <div class="layui-input-block addPermissionGroupMembersDetail">
                    <input type="text" name="userName" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item addPermissionGroupMembersDetail">
                <label class="layui-form-label">选择企业</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="enterpriseName" disabled>
                </div>
            </div>
            <div class="layui-form-item addPermissionGroupMembersDetail">
                <label class="layui-form-label">选择部门</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="deptName" disabled>
                </div>
            </div>
            <div class="layui-form-item addPermissionGroupMembersDetail">
                <label class="layui-form-label">选择岗位</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="positionName" disabled>
                </div>
            </div>
            <div class="layui-form-item addPermissionGroupMembersDetail">
                <label class="layui-form-label">工号</label>
                <div class="layui-input-block">
                    <input name="jobNumber" type="text" class="layui-input" disabled/>
                </div>
            </div>
            <div class="layui-form-item addPermissionGroupMembersDetail">
                <label class="layui-form-label">手机号</label>
                <div class="layui-input-block">
                    <input name="phone" type="text" class="layui-input" disabled/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否启用</label>
                <div class="layui-input-block">
                    <input type="checkbox" checked="" name="isDeleted" lay-skin="switch" lay-filter="switchTest"
                           lay-text="启用|不启用">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <input name="remark" type="text" class="layui-input" placeholder="备注"/>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="addPermissionGroupMembersFormSubmit" lay-submit>保存</button>
        </div>
    </div>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;

        // 渲染表格
        let mainCabinetAuthorityTb = table.render({
            elem: '#mainCabinetAuthorityTable',
            url: config.base + 'enterprisecab/cabinet/admin/authorityManage/list',
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: "序号"}
                , {field: 'name', title: '权限组名称'}
                , {field: 'quantity', title: '人员数量'}
                , {
                    field: 'oldSpecCode', title: '物料限制阈值', width: 180,
                    templet: d => {
                        if (d.creditType == "money") {
                            if (d.creditWay == "unlimited") {
                                return d.creditWayDesc + "元/" + d.lineEvaluatePeriodDesc
                            } else {
                                return d.lineOfCredit + "元/" + d.lineEvaluatePeriodDesc
                            }
                        } else {
                            if (d.creditWay == "unlimitedQuantity") {
                                return d.creditWayDesc + "/" + d.lineEvaluatePeriodDesc
                            } else {
                                return d.authorizedQuantity + "/" + d.lineEvaluatePeriodDesc
                            }
                        }
                    },
                }
                , {field: 'remark', title: '说明'}
                , {field: 'status', title: '状态', templet: d => d.status == '0' ? '正常' : '禁用'}
                , {field: 'createTime', title: '创建时间'}
                , {toolbar: '#mainCabinetAuthorityFormTableBar', title: '操作', width: 300}
            ]],
            done: function (d) {
            }
        });

        // 工具条点击事件
        table.on('tool(mainCabinetAuthorityTable)', function (obj) {
            let data = obj.data;
            if (obj.event === 'details') { //详情
                showAddPermissionsGroupForm(data, 'details');
            } else if (obj.event === 'modify') { // 修改
                showAddPermissionsGroupForm(data, 'modify');
            } else if (obj.event === 'member') {  // 成员管理
                showMemberForm(data)
            } else if (obj.event === 'disable') { // 禁用
                enableAndDisable('1', data)
            } else if (obj.event === 'enable') {  //  启用
                enableAndDisable('0', data)
            } else if (obj.event === 'delete') {
                layer.confirm('确定删除吗？', {
                    skin: 'layui-layer-admin'
                }, function (i) {
                    layer.close(i);
                    layer.load(2);
                    admin.req('enterprisecab/cabinet/admin/authorityManage/' + data.id, {}, function (data) {
                        layer.closeAll('loading');
                        if (data.code == 200) {
                            layer.msg(data.msg, {icon: 1});
                            table.reload('mainCabinetAuthorityTable');
                            layer.close(i);
                        } else {
                            layer.msg(data.msg, {icon: 2});
                        }
                    }, 'DELETE');
                });
            }
        });

        function enableAndDisable(_type, _data) {
            layer.load(2);
            admin.req('enterprisecab/cabinet/admin/authorityManage/enable/' + _data.id + '/' + _type, {}, function (res) {
                layer.closeAll('loading');
                if (res.code == 200) {
                    layer.msg(res.msg, {icon: 1});
                    table.reload('mainCabinetAuthorityTable');
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'PUT');
        }

        $('#addPermissionsGroupBtn').click(function () { // 添加权限组
            showAddPermissionsGroupForm(false)
        });
        $('#permissionsExport').click(function () {  //导出
            let checkRows = table.checkStatus('mainCabinetAuthorityTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(mainCabinetAuthorityTb.config.id, checkRows.data, 'xls');
            }
        });

        //搜索
        form.on('submit(mainCabinetAuthorityFormSearch)', function (data) {
            mainCabinetAuthorityTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });
        // 重置搜索
        form.on('submit(resets)', data => {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            let field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            mainCabinetAuthorityTb.reload({where: field, page: {curr: 1}}, 'data');
        });

        // (添加、修改、详情)权限组
        function showAddPermissionsGroupForm(data, _type) {
            let addPermissionsGroupPopUp = admin.open({
                type: 1,
                area: ['1280px', '750px'],
                offset: '85px',
                title: _type ? (_type == 'details' ? '权限组详情' : '修改权限组') : '添加权限组',
                content: $('#addPermissionsGroupForm').html(),
                success: function (_data) {
                    let ids = undefined, categoryIds = undefined, authorityManageId = undefined, isData = data;
                    let arr2treeExt;
                    let selectedData = function (treeData, targetId) {
                        for (var k = 0; k < treeData.length; k++) {
                            var nodeId = treeData[k].id;
                            if (targetId == nodeId) {
                                treeData[k].selected = true;
                                return;
                            } else {
                                if (treeData[k].children && treeData[k].children != '') {
                                    selectedData(treeData[k].children, targetId);
                                }
                            }
                        }
                    };
                    admin.req('enterprise/product/admin/productCategory/list?limit=9999&enterprise=0&page=1', {}, function (res) {
                        for (let i = 0; i < res.data.length; i++) {
                            res.data[i].children = [];
                        }
                        arr2treeExt = xmSelect.arr2tree(res.data, "parentId", "id", "children", -1);
                    }, 'get', false);

                    let selectedDataExt = function (treeData, targetId) {
                        var ids = targetId.split(",");
                        for (var k = 0; k < treeData.length; k++) {
                            var nodeId = treeData[k].id;
                            for (var t = 0; t < ids.length; t++) {
                                if (ids[t] == nodeId) {
                                    treeData[k].selected = true;
                                    continue;
                                } else {
                                    if (treeData[k].children && treeData[k].children != '') {
                                        selectedData(treeData[k].children, ids[t]);
                                    }
                                }
                            }
                        }
                    };

                    let addPermissionsGroupFormTbData = [];
                    let addPermissionsGroupFormTb = table.render({
                        elem: '#addPermissionsGroupFormTable',
                        data: addPermissionsGroupFormTbData,
                        cellMinWidth: 100,
                        limit: Number.MAX_VALUE,
                        cols: [[
                            {type: 'numbers', title: '序号', fixed: 'left'}
                            , {
                                field: 'productPic', title: '图片',
                                templet: d => d.productPic ? '<img src="' + d.productPic + '" style="cursor: pointer"/>' : '<img src="assets/images/default-icon.png" style="cursor: pointer"/>'
                            }
                            , {field: 'skuName', title: '物料名称'}
                            , {field: 'skuCode', title: '物料编号'}
                            , {field: 'oldSpecCode', title: '物料规格'}
                            , {field: 'packName', title: '包装规格'}
                            , {field: 'productBrandName', title: '所属品牌'}
                            , {field: 'unitName', title: '单位'}
                            , {
                                field: 'number', title: '限制数值', width: "150",
                                templet: d => {
                                    if (data) {
                                        if (data.creditType == 'quantity') {
                                            return `<input name="number" class='layui-input' style="width: 120px;" type='text' onkeyup="value=value.replace(/^(0+)|[^\\d]+/g,'')" value="${d.number}"/>`
                                        } else {
                                            return `<input name="amount" class='layui-input' style="width: 120px;" type='text' onkeyup="value=value.replace(/^(0+)|[^\\d]+/g,'')" value="${d.amount}"/>`
                                        }
                                    } else {
                                        if (typeof d.number !== 'undefined') {
                                            return `<input name="number" class='layui-input' style="width: 120px;" type='text' onkeyup="value=value.replace(/^(0+)|[^\\d]+/g,'')" value="${d.number}"/>`
                                        } else {
                                            return `<input name="amount" class='layui-input' style="width: 120px;" type='text' onkeyup="value=value.replace(/^(0+)|[^\\d]+/g,'')" value="${d.amount}"/>`
                                        }
                                    }

                                }
                            }
                            /*, data ? {
                                field: 'realAmount', title: data.creditType == 'money' ? '实际金额' : '实际数量',
                                templet: d => data.creditType == 'money' ? d.realAmount : d.realNumber
                            } : ''*/
                            , {align: 'center', toolbar: '#addPermissionsGroupFormTableBar', title: '操作'}
                        ]],
                        done: function (res, curr, count) {
                            if (_type == 'details') {
                                $('#addPermissionsGroupFormTableBox input').attr('disabled', 'disabled')
                            }
                        }
                    });

                    table.on('tool(addPermissionsGroupFormTable)', function (obj) {
                        let data = obj.data;
                        if (obj.event === 'delete') { // 删除
                            addPermissionsGroupFormTbData.splice($(obj.tr[0]).attr('data-index'), 1);
                            table.reload('addPermissionsGroupFormTable', {data: addPermissionsGroupFormTbData});
                        }
                    });

                    $("#addPermissionsGroupFormTableBox").delegate("input[name='number']", "blur", function () {
                        if (addPermissionsGroupFormTbData[$(this).parents('tr').index()]) {
                            addPermissionsGroupFormTbData[$(this).parents('tr').index()].number = $(this).val();
                            addPermissionsGroupFormTbData[$(this).parents('tr').index()].amount = '';
                        }
                    });
                    $("#addPermissionsGroupFormTableBox").delegate("input[name='amount']", "blur", function () {
                        if (addPermissionsGroupFormTbData[$(this).parents('tr').index()]) {
                            addPermissionsGroupFormTbData[$(this).parents('tr').index()].amount = $(this).val();
                            addPermissionsGroupFormTbData[$(this).parents('tr').index()].number = '';
                        }
                    });


                    $('#lineOfCredit').blur(function () {
                        addPermissionsGroupFormTbData.forEach(item => {
                            item.amount = $(this).val() || '';
                            delete item.number;
                        });

                        table.reload('addPermissionsGroupFormTable', {data: addPermissionsGroupFormTbData});
                    });

                    $('#authorizedQuantity').blur(function () {
                        addPermissionsGroupFormTbData.forEach(item => {
                            item.number = $(this).val() || '';
                            delete item.amount;
                        });
                        table.reload('addPermissionsGroupFormTable', {data: addPermissionsGroupFormTbData});
                    });

                    //领新授信类型选择
                    form.on('radio(creditType)', function (data) {
                        creditType(data.value);
                        creditAmountQuantityFn(data.value);
                        authotizedStatusFn(data.value);
                        moneyAndQuantityThreshold(data.value);
                        lineOfCreditAndQuantityThreshold(data.value);
                        if (isData) {
                            practicalCreditFn(data.value,$('select[name="creditWay"]').val());
                        } else {
                            practicalCreditFn();
                        }
                    });

                    //授信方式操作
                    form.on('select(creditWay)', function (data) {
                        lineOfCreditAndQuantityThreshold(data.value, $('input[name="authotizedStatus"]:checked').val());
                        creditAmountQuantityFn(data.value);
                        authotizedStatusFn(data.value);
                        practicalCreditFn($('input[name="creditType"]:checked').val(),data.value);
                    });

                    //是否限制物料操作
                    form.on('select(astrictMaterial)', function (data) {
                        restrictWayFn(data.value);
                        materialIdBox(data.value);
                        addPermissionsGroupAddFn(false);
                        isShowTable(data.value);
                    });

                    //限制方式操作
                    form.on('radio(materiel)', function (data) {
                        materialIdBox(data.value);
                        addPermissionsGroupAddFn(data.value);
                        isShowTable(data.value);
                    });

                    form.on('radio(authotizedStatus)', function (data) {
                        lineOfCreditAndQuantityThreshold($('select[name="creditWay"]').val(), data.value)
                    });


                    /*
                    * 授信方式渲染
                    * */
                    function creditType(_type) {
                        let selectMoneyData = [
                                {name: '组员共享领用金额', value: 'share'},
                                {name: '组员独立授信领用金额', value: 'independent'},
                                {name: '不限制领用金额', value: 'unlimited'},
                            ],
                            selectQuantityData = [
                                {name: '组员共享领用数量', value: 'shareQuantity'},
                                {name: '组员独立授信领用数量', value: 'independentQuantity'},
                                {name: '不限制领用数量', value: 'unlimitedQuantity'},
                            ];
                        if (_type == "money") {
                            loadSelectHtmlNew(selectMoneyData, '请选择授信方式', 'creditWay', '[lay-filter="addPermissionsGroupForm"]', 3)
                        } else if (_type == "quantity") {
                            loadSelectHtmlNew(selectQuantityData, '请选择授信方式', 'creditWay', '[lay-filter="addPermissionsGroupForm"]', 3)
                        }
                    }

                    // 未归还金额阈值 未归还数量阈值
                    function moneyAndQuantityThreshold(_type) {
                        if (_type == "money") {
                            $('#moneyThresholdBox').css('display', 'block');
                            $('#moneyThresholdBox input[name="moneyThreshold"]').attr('lay-verify', 'number');

                            $('#quantityThresholdBox').css('display', 'none');
                            $('#quantityThresholdBox input[name="quantityThreshold"]').removeAttr('lay-verify');
                            $('#quantityThresholdBox input[name="quantityThreshold"]').val('');

                        } else if (_type == "quantity") {
                            $('#quantityThresholdBox').css('display', 'block');
                            $('#quantityThresholdBox input[name="quantityThreshold"]').attr('lay-verify', 'number');

                            $('#moneyThresholdBox').css('display', 'none');
                            $('#moneyThresholdBox input[name="moneyThreshold"]').removeAttr('lay-verify');
                            $('#moneyThresholdBox input[name="moneyThreshold"]').val('');
                        }
                    }

                    // 物料金额限制阈值 物料数量限制阈值
                    function lineOfCreditAndQuantityThreshold(_type, _number) {
                        if (_type == "money") {
                            $('#lineOfCreditBox').css('display', 'block');
                            $('#lineOfCredit').attr('lay-verify', 'number');
                            $('#authorizedQuantityBox').css('display', 'none');
                            $('#authorizedQuantity').removeAttr('lay-verify');
                            $('#authorizedQuantity').val('');

                        } else if (_type == "quantity") {
                            $('#authorizedQuantityBox').css('display', 'block');
                            $('#authorizedQuantity').attr('lay-verify', 'number');
                            $('#lineOfCreditBox').css('display', 'none');
                            $('#lineOfCredit').removeAttr('lay-verify');
                            $('#lineOfCredit').val('');
                        } else if (_type == "unlimited") {
                            $('#lineOfCreditBox').css('display', 'none');
                            $('#lineOfCredit').removeAttr('lay-verify');
                            $('#lineOfCredit').val('');
                            $('#addPermissionsGroupFormTableBox input[name="amount"]').val(0);
                            $('#addPermissionsGroupFormTableBox input[name="number"]').val(0);
                        } else if (_type == "unlimitedQuantity") {
                            $('#authorizedQuantityBox').css('display', 'none');
                            $('#authorizedQuantity').removeAttr('lay-verify');
                            $('#authorizedQuantity').val('');
                            $('#addPermissionsGroupFormTableBox input[name="amount"]').val(0);
                            $('#addPermissionsGroupFormTableBox input[name="number"]').val(0);
                        } else {
                            if (_number == 0) {
                                if ($('input[name="creditType"]:checked').val() == 'money') {
                                    $('#lineOfCreditBox').css('display', 'block');
                                    $('#lineOfCredit').attr('lay-verify', 'number');
                                    $('#authorizedQuantityBox').css('display', 'none');
                                    $('#authorizedQuantity').removeAttr('lay-verify');
                                    $('#authorizedQuantity').val(0);
                                } else if ($('input[name="creditType"]:checked').val() == 'quantity') {
                                    $('#authorizedQuantityBox').css('display', 'block');
                                    $('#authorizedQuantity').attr('lay-verify', 'number');
                                    $('#lineOfCreditBox').css('display', 'none');
                                    $('#lineOfCredit').removeAttr('lay-verify');
                                    $('#lineOfCredit').val(0);
                                }
                            } else if (_number == "1") {
                                $('#lineOfCreditBox').css('display', 'none');
                                $('#lineOfCredit').removeAttr('lay-verify');
                                $('#lineOfCredit').val(0);
                                $('#authorizedQuantityBox').css('display', 'none');
                                $('#authorizedQuantity').removeAttr('lay-verify');
                                $('#authorizedQuantity').val(0);
                            }

                        }

                        // $('#addPermissionsGroupFormTableBox input[name="amount"]').val(0);
                        // $('#addPermissionsGroupFormTableBox input[name="number"]').val(0);

                        if ($('#addPermissionsGroupFormTableBox input[name="number"]').is('*')) {
                            $('#addPermissionsGroupFormTableBox input[name="amount"]').val(0);
                        } else if ($('#addPermissionsGroupFormTableBox input[name="amount"]').is('*')) {
                            $('#addPermissionsGroupFormTableBox input[name="number"]').val(0);
                        } else {
                            $('#addPermissionsGroupFormTableBox input[name="amount"]').val(0);
                            $('#addPermissionsGroupFormTableBox input[name="number"]').val(0);
                        }

                        addPermissionsGroupFormTbData.forEach(item => {
                            if (_type == "money" || _type == "share" || _type == "independent") {
                                item.number = 0;
                            } else if (_type == "quantity" || _type == "shareQuantity" || _type == "independentQuantity") {
                                item.amount = 0;
                            } else {
                                item.number = 0;
                                item.amount = 0;
                            }

                        });
                    }

                    // 是否限制物料（显示不显示）
                    function astrictMaterialFn(_type) {
                        if (_type === 'unlimited' || _type === 'unlimitedQuantity') {
                            $('#astrictMaterialBox').hide()
                        } else {
                            $('#astrictMaterialBox').show();
                        }
                    }

                    // 限制方式（显示不显示）
                    function restrictWayFn(_type) {
                        if (_type === 'unlimited' || _type === 'unlimitedQuantity') {
                            $('#restrictWayBox').hide();
                            $('#restrictWayBox  input[name="restrictWay"]').removeAttr('checked');
                        } else if (_type === 'noAstrict') {
                            $('#restrictWayBox').hide();
                            $('#restrictWayBox  input[name="restrictWay"]').removeAttr('checked');
                        } else {
                            $('#restrictWayBox').show();
                            $('#restrictWayBox  input[name="restrictWay"]').eq(0).prop('checked', 'true');
                        }
                        form.render('radio');
                    }

                    let smlSelectInstansExt = xmSelect.render({
                        el: '#materialId',
                        model: {label: {type: 'text'}},
                        clickClose: true,
                        filterable: true,
                        layVerify: 'required',
                        disabled: data ? (_type == 'details' ? true : false) : false,
                        tree: {
                            show: true,
                            strict: false,
                            expandedKeys: [-1],
                        },
                        tips: '顶级分类',
                        prop: {
                            name: 'name',
                            value: 'id',
                            children: 'children'
                        },
                        data() {
                            //填充数据
                            return arr2treeExt;
                        },
                        on: function (data) {
                            let id = '';
                            for (var j = 0; j < data.arr.length; j++) {
                                if (j == 0) {
                                    id = data.arr[j].id
                                } else {
                                    id += ',' + data.arr[j].id;
                                }
                            }
                            $("input[name='materialId']").val(id);

                            layer.load(2);
                            admin.req('enterprisecab/cabinet/admin/authorityManage/findMateriel', {
                                page: 1,
                                limit: 99999,
                                categoryIds: id
                            }, res => {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    res.data.forEach(item => {
                                        item.manageld = '';
                                        item.id = void 0;
                                        if ($('input[name="authorizedQuantity"]').val() > 0) {
                                            item.number = $('input[name="authorizedQuantity"]').val();
                                        } else if ($('input[name="lineOfCredit"]').val()) {
                                            item.amount = $('input[name="lineOfCredit"]').val();
                                        } else {
                                            item.number = '';
                                            item.amount = '';
                                        }
                                        item.colsIsShow = false;
                                    });

                                    addPermissionsGroupFormTbData = res.data;
                                    table.reload('addPermissionsGroupFormTable', {data: addPermissionsGroupFormTbData});
                                }
                            })
                        }
                    });

                    //可领物资分类（显示不显示）
                    function materialIdBox(_type) {
                        if (_type === 'unlimited' || _type === 'unlimitedQuantity') {
                            $('#materialIdBox').hide();
                            $('#materialIdBox input').val('');
                            smlSelectInstansExt.setValue([]);
                            smlSelectInstansExt.update({layVerify: ''});
                        } else if (_type === 'noAstrict') {
                            $('#materialIdBox').hide();
                            $('#materialIdBox input').val('');
                            smlSelectInstansExt.setValue([]);
                            smlSelectInstansExt.update({layVerify: ''});
                        } else if (_type === 'materiel') {
                            $('#materialIdBox').hide();
                            $('#materialIdBox input').val('');
                            smlSelectInstansExt.setValue([]);
                            smlSelectInstansExt.update({layVerify: ''});
                        } else {
                            $('#materialIdBox').show();
                            smlSelectInstansExt.update({layVerify: 'required'})
                        }
                    }

                    // 添加限制物料按钮（显示不显示）
                    function addPermissionsGroupAddFn(_type) {
                        if (_type === 'unlimited' || _type === 'unlimitedQuantity') {
                            $('#addPermissionsGroupAdd').hide();
                        } else if (_type === 'noAstrict') {
                            $('#addPermissionsGroupAdd').hide();
                        } else if (_type === 'category') {
                            $('#addPermissionsGroupAdd').hide();
                        } else if (_type === false) {
                            $('#addPermissionsGroupAdd').hide();
                        } else {
                            $('#addPermissionsGroupAdd').show();
                        }
                    }

                    //是否限制单物料领用(金额/数量)
                    function authotizedStatusFn(_type) {
                        if (_type == 'quantity') {
                            $('#authotizedStatusBox').show();
                            $('#authotizedStatusLabel').text('单物料领用数量');
                        } else if (_type == 'money') {
                            $('#authotizedStatusBox').show();
                            $('#authotizedStatusLabel').text('单物料领用金额');
                        } else if (_type == 'unlimited' || _type == 'unlimitedQuantity') {
                            $('#authotizedStatusBox').hide();
                            $('#authotizedStatusBox  input[name="authotizedStatus"]').eq(0).prop('checked', 'true');
                        } else if (_type == 'shareQuantity' || _type == 'independentQuantity' || _type == 'share' || _type == 'independent') {
                            $('#authotizedStatusBox').show();
                        }
                        form.render('radio');
                    }

                    function creditAmountQuantityFn(_type) {
                        if (_type == 'quantity') {
                            $('#creditAmountQuantityLabel').text('标准授信数量');
                            $('input[name="creditQuantity"]').show();
                            $('input[name="creditQuantity"]').attr('lay-verify', 'number');

                            $('input[name="creditAmount"]').val('');
                            $('input[name="creditAmount"]').hide();
                            $('input[name="creditAmount"]').removeAttr('lay-verify');

                        } else if (_type == 'money') {
                            $('#creditAmountQuantityLabel').text('标准授信额度');
                            $('input[name="creditAmount"]').show();
                            $('input[name="creditAmount"]').attr('lay-verify', 'number');

                            $('input[name="creditQuantity"]').val('');
                            $('input[name="creditQuantity"]').hide();
                            $('input[name="creditQuantity"]').removeAttr('lay-verify');
                        } else if (_type == 'unlimited' || _type == 'unlimitedQuantity') {
                            $('#creditAmountQuantityBox').hide();
                            $('input[name="creditQuantity"]').val('');
                            $('input[name="creditQuantity"]').hide();
                            $('input[name="creditQuantity"]').removeAttr('lay-verify');
                            $('input[name="creditAmount"]').val('');
                            $('input[name="creditAmount"]').hide();
                            $('input[name="creditAmount"]').removeAttr('lay-verify');
                        } else if (_type == 'share' || _type == 'independent') {
                            $('#creditAmountQuantityBox').show();
                            $('input[name="creditQuantity"]').val('');
                            $('input[name="creditQuantity"]').hide();
                            $('input[name="creditQuantity"]').removeAttr('lay-verify');

                            $('input[name="creditAmount"]').show();
                            $('input[name="creditAmount"]').attr('lay-verify', 'number');
                        } else if (_type == 'shareQuantity' || _type == 'independentQuantity') {
                            $('#creditAmountQuantityBox').show();

                            $('input[name="creditQuantity"]').show();
                            $('input[name="creditQuantity"]').attr('lay-verify', 'number');

                            $('input[name="creditAmount"]').val('');
                            $('input[name="creditAmount"]').hide();
                            $('input[name="creditAmount"]').removeAttr('lay-verify');
                        }
                    }

                    let cabinetBox = xmSelect.render({
                        el: '#cabinetBox',
                        filterable: true,
                        autoRow: true,
                        layVerify: 'required',
                        template({item, sels, name, value}) {
                            return "<span class='colorBlack'>" + item.cabCode + "</span>"
                        },
                        filterMethod: function (val, item, index, prop) {
                            if (item.cabCode.toLowerCase().indexOf(val.toLowerCase()) != -1) {//把value相同的搜索出来
                                return true;
                            }
                            return false;
                        },
                        prop: {
                            name: 'cabCode',
                            value: 'id',
                        },
                        data: [],
                        initValue: data ? data.cabinetId.split(',') : [],
                        disabled: _type == 'details' ? true : false,
                        on: function (data) {
                            let id = '';
                            let code = '';
                            data.arr.forEach((item, index) => {
                                if (index == 0) {
                                    id += item.id;
                                    code += item.cabCode;
                                } else {
                                    id += ',' + item.id;
                                    code += ',' + item.cabCode;
                                }
                                $("input[name='cabinetId']").val(id);
                                $("input[name='cabinetCode']").val(code);
                            })
                        }
                    });

                    admin.req('enterprisecab/cabinet/admin/cabinet/list?cabinetNature=main&cabinetTypeId=&cabinetBrandId=&status=&code=&cabinetType=spring', {}, res => {
                        if (res.code === 200) {
                            cabinetBox.update({data: res.data});
                        } else {
                            cabinetBox.update({data: [],})
                        }
                    });


                    //添加限制物料
                    function addPermissionsGroupAddPup() {
                        if (addPermissionsGroupFormTbData.length > 0) {
                            ids = '';
                            addPermissionsGroupFormTbData.forEach((item, index) => {
                                if ((index + 1) === addPermissionsGroupFormTbData.length) {
                                    ids += item.skuCode;
                                } else {
                                    ids += item.skuCode + ",";
                                }
                            })
                        }

                        let addRestrictedMaterialsPopUp = admin.open({
                            type: 1,
                            area: ['1200px', '820px'],
                            offset: '65px',
                            title: '添加限制物料',
                            content: $('#addRestrictedMaterialsTemplate').html(),
                            success: function (_data) {
                                let addRestrictedMaterialsFormTb = table.render({
                                    elem: '#addRestrictedMaterialsFormTable',
                                    url: config.base + 'enterprisecab/cabinet/admin/authorityManage/findMateriel',
                                    page: true,
                                    where: {ids, categoryIds},
                                    limit: 5,
                                    limits: [5, 10, 20, 30, 40, 50, 60, 70, 80],
                                    cellMinWidth: 100,
                                    cols: [[
                                        {type: 'checkbox'}
                                        , {
                                            field: 'productPic',
                                            title: '图片',
                                            templet: d => d.productPic ? '<img src="' + d.productPic + '" style="cursor: pointer"/>' : '<img src="assets/images/default-icon.png"/>'
                                        }
                                        , {field: 'skuName', title: '物料名称'}
                                        , {field: 'skuCode', title: '物料编号'}
                                        , {field: 'oldSpecCode', title: '物料规格'}
                                        , {field: 'packName', title: '包装规格'}
                                        , {field: 'productBrandName', title: '所属品牌'}
                                        , {field: 'unitName', title: '单位'}
                                    ]],
                                    done: function () {
                                        $('[lay-filter="addRestrictedMaterialsForm"] .layui-table-body input').attr('disabled', 'disabled');
                                    }
                                });

                                table.on('row(addRestrictedMaterialsFormTable)', function (obj) {
                                    let flag = !obj.tr.find(':checkbox:first').prop('checked');
                                    obj.tr.find(':checkbox').prop('checked', flag);
                                    if (flag) {
                                        obj.tr.find('.layui-form-checkbox').addClass('layui-form-checked');  //设置复选框选中样式
                                    } else {
                                        obj.tr.find('.layui-form-checkbox').removeClass('layui-form-checked');//取消复选框选中样式
                                    }
                                    layui.each(table.cache.addRestrictedMaterialsFormTable, function (i, l) {
                                        if (obj.tr.index() == l.LAY_TABLE_INDEX) {
                                            l.LAY_CHECKED = flag;
                                        }
                                    });
                                })


                                $('#addRestrictedMaterialsFormSubmit').click(function () {
                                    let checkStatus = table.checkStatus('addRestrictedMaterialsFormTable');
                                    if (checkStatus.data.length === 0) {
                                        layer.msg('请选择需要导出的数据', {icon: 5});
                                        return false;
                                    }
                                    checkStatus.data.forEach(item => {
                                        item.manageld = '';
                                        item.id = void 0;
                                        if ($('input[name="authorizedQuantity"]').val() > 0) {
                                            item.number = $('input[name="authorizedQuantity"]').val();
                                        } else if ($('input[name="lineOfCredit"]').val()) {
                                            item.amount = $('input[name="lineOfCredit"]').val();
                                        } else {
                                            item.number = '';
                                            item.amount = ''
                                        }
                                        item.colsIsShow = true;
                                    });

                                    addPermissionsGroupFormTbData = [...addPermissionsGroupFormTbData, ...checkStatus.data];

                                    table.reload('addPermissionsGroupFormTable', {data: addPermissionsGroupFormTbData});
                                    layer.close(addRestrictedMaterialsPopUp);
                                });

                                // 搜索
                                form.on('submit(addRestrictedMaterialsFormSearch)', function (data) {
                                    addRestrictedMaterialsFormTb.reload({where: data.field, page: {curr: 1}}, 'data');
                                });

                            }


                        });
                    }

                    function isShowTable(_type) {
                        if (_type === 'unlimited' || _type === 'unlimitedQuantity') {
                            addPermissionsGroupFormTbData = [];
                            table.reload('addPermissionsGroupFormTable', {data: addPermissionsGroupFormTbData});
                        } else if (_type === 'noAstrict') {
                            addPermissionsGroupFormTbData = [];
                            table.reload('addPermissionsGroupFormTable', {data: addPermissionsGroupFormTbData});
                        } else if (_type === 'materiel' || _type === 'category') {
                            addPermissionsGroupFormTbData = [];
                            table.reload('addPermissionsGroupFormTable', {data: addPermissionsGroupFormTbData});
                        }

                    }

                    admin.reqSync('user/admin/user/list?limit=99999', {}, res => {
                        if (res.code === 200) {
                            loadSelectHtmlNew(res.data, '请选择超额审核人', 'excessAuditor', '[lay-filter="addPermissionsGroupForm"]', 7);
                            loadSelectHtmlNew(res.data, '请选择超额复审审核人', 'recheckAmountAuditor', '[lay-filter="addPermissionsGroupForm"]', 7);
                        } else {
                            loadSelectHtmlNew([], '请选择超额审核人', 'excessAuditor', '[lay-filter="addPermissionsGroupForm"]', 7);
                            loadSelectHtmlNew([], '请选择超额复审审核人', 'recheckAmountAuditor', '[lay-filter="addPermissionsGroupForm"]', 7)
                        }
                    });
                    //领料超额预警
                    form.on('radio(isExcessStatus)', function (data) {
                        receiveNewExcess(data.value)
                    });
                    form.on('select(recheckAmountAuditorFn)', function (data) {
                        if (data.value) {
                            let newData = JSON.parse($(data.elem[data.elem.selectedIndex]).attr('data'));
                            $('[lay-filter="addPermissionsGroupForm"] input[name="email"]').val(newData.email);
                        } else {
                            $('[lay-filter="addPermissionsGroupForm"] input[name="email"]').val();
                        }
                    });


                    function receiveNewExcess(_value) {
                        if (_value == 0) {
                            $('.receiveNewExcess').show();
                            $('.receiveNewExcessRequired input').attr('lay-verify', 'required');
                            $('.receiveNewExcessRequired select').attr('lay-verify', 'required');
                        } else {
                            $('.receiveNewExcess').hide();
                            $('.receiveNewExcess input').val('');
                            $('.receiveNewExcess select').val('');
                            $('.receiveNewExcessRequired input').removeAttr('lay-verify');
                            $('.receiveNewExcessRequired select').removeAttr('lay-verify');
                            form.render('select');
                        }
                    }

                    // 实际授信 (金额/数量)
                    function practicalCreditFn(_type, _kind) {
                        if (isData) {
                            if (_type == 'money' && _kind == 'share') {
                                $('#practicalLineOfCreditBox').show();
                                $('#practicalCreditQuantityBox').hide();
                            } else if (_type == 'quantity' && _kind == 'shareQuantity') {
                                $('#practicalCreditQuantityBox').show();
                                $('#practicalLineOfCreditBox').hide();
                            } else {
                                $('#practicalLineOfCreditBox').hide();
                                $('#practicalCreditQuantityBox').hide();
                            }
                        } else {
                            $('#practicalLineOfCreditBox').hide();
                            $('#practicalCreditQuantityBox').hide();
                        }
                    }


                    if (data) {
                        data.status = data.status == 0 ? 'on' : '';
                        creditType(data.creditType);
                        moneyAndQuantityThreshold(data.creditType);
                        lineOfCreditAndQuantityThreshold(data.creditType);
                        restrictWayFn(data.astrictMaterial);
                        receiveNewExcess(data.excessStatus);
                        practicalCreditFn(data.creditWay, data.creditType);
                        creditAmountQuantityFn(data.creditWay);
                        $('input[name="creditType"]').attr('disabled','disabled');
                        $('select[name="creditWay"]').attr('disabled','disabled');
                        if (data.astrictMaterial === 'astrict') {
                            addPermissionsGroupAddFn(data.restrictWay);
                            materialIdBox(data.restrictWay);
                        } else {
                            addPermissionsGroupAddFn(false);
                            materialIdBox(data.astrictMaterial)
                        }

                        if (data.creditWay == 'unlimited' || data.creditWay == 'unlimitedQuantity') {
                            authotizedStatusFn(data.creditWay);
                            lineOfCreditAndQuantityThreshold(data.creditWay);
                        } else {
                            authotizedStatusFn(data.creditType);
                            if (data.authotizedStatus == '1') {
                                lineOfCreditAndQuantityThreshold(data.creditWay, data.authotizedStatus);
                            }
                        }

                        if (_type == 'details') {
                            $('[lay-filter="addPermissionsGroupForm"] input').attr('disabled', 'disabled');
                            $('[lay-filter="addPermissionsGroupForm"] select').attr('disabled', 'disabled');
                            $('[lay-filter="addPermissionsGroupForm"] input').css('borderColor', 'transparent');
                            $('button[lay-filter="addPermissionsGroupFormSubmit"]').remove();
                            $('#addPermissionsGroupAdd').remove();
                        } else {
                            $('form[lay-filter="addPermissionsGroupForm"]  input[name="name"]').attr('disabled', 'disabled');

                            //添加限制物料
                            $('#addPermissionsGroupAdd').click(function () {
                                addPermissionsGroupAddPup();
                            });

                            form.on('submit(addPermissionsGroupFormSubmit)', function (d) {
                                let authorityMaterielList = [];
                                addPermissionsGroupFormTbData.forEach(item => {
                                    let obj = {};
                                    obj.skuCode = item.skuCode;
                                    obj.id = item.id;
                                    // obj.categoryld = item.id;
                                    obj.categoryId = item.productCategoryId;

                                    if (item.manageId) {
                                        obj.manageld = item.manageId;
                                    } else {
                                        obj.manageld = '';
                                    }
                                    if (d.field.lineOfCredit && d.field.lineOfCredit > 0) {
                                        obj.amount = item.amount;
                                    } else {
                                        obj.number = item.number
                                    }
                                    authorityMaterielList.push(obj)
                                });
                                layer.load(2);
                                //d.field.cabinetId = cabinetData.id;
                                //d.field.cabinetCode = cabinetData.cabCode;
                                d.field.status = d.field.status == 'on' ? 0 : 1;
                                d.field.authorityMaterielList = authorityMaterielList;

                                admin.req('enterprisecab/cabinet/admin/authorityManage/update', JSON.stringify(d.field), function (res) {
                                    layer.closeAll('loading');
                                    if (res.code == 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('mainCabinetAuthorityTable');
                                        layer.close(addPermissionsGroupPopUp);
                                    } else {
                                        layer.msg(res.msg, {icon: 2});
                                    }
                                }, 'PUT', true, 'application/json; charset=utf-8');
                                return false
                            });
                        }


                        form.val('addPermissionsGroupForm', data);
                        let recheckAmountAuditorData = $('select[lay-filter="recheckAmountAuditorFn"] option:selected').attr('data');
                        let emailData = recheckAmountAuditorData ? JSON.parse(recheckAmountAuditorData).email : '';
                        $('[lay-filter="addPermissionsGroupForm"] input[name="email"]').val(emailData);
                        selectedDataExt(arr2treeExt, data.materialId);
                        smlSelectInstansExt.setValue(data.materialId.split(","));


                        authorityManageId = data.id;

                        admin.req('enterprisecab/cabinet/admin/authorityManage/findMateriel', {
                            ids,
                            categoryIds,
                            authorityManageId
                        }, res => {
                            if (res.code === 200) {
                                res.data.forEach(item => {
                                    if (data.restrictWay == 'materiel' && _type == 'modify') {
                                        item.colsIsShow = true;
                                    }
                                    addPermissionsGroupFormTbData.push(item)

                                });

                                table.reload('addPermissionsGroupFormTable', {data: addPermissionsGroupFormTbData});
                            }
                        });


                    } else {

                        //添加限制物料
                        $('#addPermissionsGroupAdd').click(function () {
                            addPermissionsGroupAddPup();
                        });
                        form.on('submit(addPermissionsGroupFormSubmit)', function (d) {
                            let authorityMaterielList = [];
                            addPermissionsGroupFormTbData.forEach(item => {
                                let obj = {};
                                obj.skuCode = item.skuCode;
                                obj.categoryId = item.productCategoryId;

                                obj.manageld = '';
                                if (d.field.lineOfCredit) {
                                    obj.amount = item.amount;
                                } else {
                                    obj.number = item.number
                                }
                                authorityMaterielList.push(obj)
                            });
                            layer.load(2);
                            //d.field.cabinetId = cabinetData.id;
                            //d.field.cabinetCode = cabinetData.cabCode;
                            d.field.status = d.field.status == 'on' ? 0 : 1;
                            d.field.authorityMaterielList = authorityMaterielList;

                            admin.req('enterprisecab/cabinet/admin/authorityManage/add', JSON.stringify(d.field), function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    table.reload('mainCabinetAuthorityTable');
                                    layer.close(addPermissionsGroupPopUp);
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'POST', true, 'application/json; charset=utf-8');
                            return false
                        });
                    }
                    form.render();
                }
            })
        }

        /*权限 --》成员管理*/
        function showMemberForm(data) {
            admin.open({
                type: 1,
                area: ['1400px', '700px'],
                offset: '75px',
                title: '设备权限组成员管理',
                content: $('#memberForm').html(),
                success: function (_data) {
                    let permissionsData = data;
                    let memberFormTB = table.render({
                        elem: '#memberFormTable',
                        url: config.base + 'enterprisecab/cabinet/admin/authorityMember/list?authorityManageId=' + data.id,
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'checkbox'}
                            , {field: 'userName', title: '成员姓名'}
                            , {field: 'jobNumber', title: '工号'}
                            , {field: 'phone', title: '电话'}
                            , {field: 'enterpriseName', title: '所属公司'}
                            , {field: 'deptName', title: '所属部门'}
                            , {field: 'positionName', title: '所属岗位'}
                            , {field: '', title: '所属权限组(以主柜面板为单位)', templet: d => data.name}
                            , {field: 'isDeleted', title: '状态', templet: d => d.isDeleted ? '正常' : '禁用'}
                            , {field: 'createTime', title: '创建时间'}
                            , {field: 'creatorName', title: '添加人'}
                            , {toolbar: '#memberFormTableBar', title: '操作'}
                        ]],
                    });

                    // 工具条点击事件
                    table.on('tool(memberFormTable)', function (obj) {
                        let data = obj.data;
                        if (obj.event === 'details') { //详情
                            showAddPermissionGroupMembersForm('details', Object.assign(permissionsData, data));
                        } else if (obj.event === 'delete') {  //删除
                            layer.confirm('确定要删除吗？', {
                                offset: '65px',
                                skin: 'layui-layer-admin'
                            }, function (i) {
                                layer.close(i);
                                layer.load(2);
                                admin.req('enterprisecab/cabinet/admin/authorityMember/' + data.id, {}, res => {
                                    layer.closeAll('loading');
                                    if (res.code == 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('memberFormTable');
                                    } else {
                                        layer.msg(res.msg, {icon: 2});
                                    }
                                }, 'DELETE')
                            });
                        }
                    });


                    $('#memberFormBatchDeletion').click(function () { // 批量操作
                        let checkRows = table.checkStatus('memberFormTable');
                        if (checkRows.data.length == 0) {
                            layer.msg('请选择要删除的数据', {icon: 2});
                        } else {
                            new Promise((resolve, reject) => {
                                let ids = '';
                                checkRows.data.forEach(item => {
                                    ids += item.id + ','
                                });
                                resolve(ids.substr(0, ids.length - 1));
                            }).then(rData => {
                                layer.load(2);
                                admin.req('enterprisecab/cabinet/admin/authorityMember/batchIds', {ids: rData.split(',')}, res => {
                                    layer.closeAll('loading');
                                    if (res.code == 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('memberFormTable');
                                    } else {
                                        layer.msg(res.msg, {icon: 2});
                                    }
                                }, 'DELETE')
                            });
                        }
                    });
                    $('#addMembersBtn').click(function () { // 添加权限组成员
                        showAddPermissionGroupMembersForm('add', data)
                    });

                    $('#memberFormExport').click(function () {  //导出
                        let checkRows = table.checkStatus('memberFormTable');
                        if (checkRows.data.length == 0) {
                            layer.msg('请选择要导出的数据', {icon: 2});
                        } else {
                            table.exportFile(memberFormTB.config.id, checkRows.data, 'xls');
                        }
                    })

                    //搜索
                    form.on('submit(memberFormSearch)', function (data) {
                        memberFormTB.reload({where: data.field, page: {curr: 1}}, 'data');
                    });

                }
            })
        }

        //  添加权限组成员
        function showAddPermissionGroupMembersForm(_type, data) {
            let thatData = data;
            let addPermissionGroupMembersPopUp = admin.open({
                type: 1,
                area: ['1200px', '750px'],
                offset: '85px',
                title: _type === 'details' ? '权限组成员详情' : '添加权限组成员',
                content: $('#addPermissionGroupMembers').html(),
                success: function (_data) {

                    $('#addPermissionGroupMembersFormAuthorizedQuantityBox').hide();
                    $('#addPermissionGroupMembersFormAuthorizedQuantityBox>input[name="authorizedQuantity"]').val('');
                    $('#addPermissionGroupMembersFormLineOfCreditBox').hide();
                    $('#addPermissionGroupMembersFormLineOfCreditBox>input[name="authorizedQuantity"]').val('');

                    if (data.creditType == "money") {
                        if (data.creditWay == 'unlimited') {
                            $('#addPermissionGroupMembersFormLineOfCreditBox').hide()
                        } else {
                            $('#addPermissionGroupMembersFormLineOfCreditBox').show()
                        }
                    } else if (data.creditType == "quantity") {
                        if (data.creditWay == 'unlimitedQuantity') {
                            $('#addPermissionGroupMembersFormAuthorizedQuantityBox').hide()
                        } else {
                            $('#addPermissionGroupMembersFormAuthorizedQuantityBox').show()
                        }
                    }

                    if (data.astrictMaterial == 'noAstrict') {
                        // $('#materialId1Box').hide()
                    } else {
                        // $('#materialId1Box').show()
                    }


                    let enterpriseName = '', deptName = '', positionName = '', userName = '';

                    let arr2treeExt;
                    let selectedData = function (treeData, targetId) {
                        for (var k = 0; k < treeData.length; k++) {
                            var nodeId = treeData[k].id;
                            if (targetId == nodeId) {
                                treeData[k].selected = true;
                                return;
                            } else {
                                if (treeData[k].children && treeData[k].children != '') {
                                    selectedData(treeData[k].children, targetId);
                                }
                            }
                        }
                    };
                    admin.req('enterprise/knife/admin/productCategoryKnife/list?limit=9999&enterprise=0&page=1', {}, function (res) {
                        for (let i = 0; i < res.data.length; i++) {
                            res.data[i].children = [];
                        }
                        arr2treeExt = xmSelect.arr2tree(res.data, "parentId", "id", "children", -1);
                    }, 'get', false);

                    let selectedDataExt = function (treeData, targetId) {
                        var ids = targetId.split(",");
                        for (var k = 0; k < treeData.length; k++) {
                            var nodeId = treeData[k].id;
                            for (var t = 0; t < ids.length; t++) {
                                if (ids[t] == nodeId) {
                                    treeData[k].selected = true;
                                    continue;
                                } else {
                                    if (treeData[k].children && treeData[k].children != '') {
                                        selectedData(treeData[k].children, ids[t]);
                                    }
                                }
                            }
                        }
                    };

                    if (_type === 'details') {
                        form.val('addPermissionGroupMembersForm', data);
                        selectedDataExt(arr2treeExt, data.materialId);
                        $('.addPermissionGroupMembersDetail').show();
                        $('#userIdBox').hide();
                        $('[lay-filter="addPermissionGroupMembersForm"] input').attr('disabled', 'disabled');
                        $('[lay-filter="addPermissionGroupMembersForm"] input').css('borderColor', 'transparent');
                        $('[lay-filter="addPermissionGroupMembersForm"] input').css('', 'transparent');
                        $('button[lay-filter="addPermissionGroupMembersFormSubmit"]').hide();
                    } else {
                        data.remark = '';
                        data.jobNumber = '';
                        data.phone = '';
                        data.isDeleted = true;
                        form.val('addPermissionGroupMembersForm', data);
                        selectedDataExt(arr2treeExt, data.materialId);

                        // 提交
                        let formDataList = new Map();
                        form.on('submit(addPermissionGroupMembersFormSubmit)', function (d) {
                            layer.load(2);
                            let pushDataList = [];
                            formDataList.forEach((value, key) => {
                                let obj = {
                                    name: d.field.name,
                                    lineOfCredit: d.field.lineOfCredit,
                                    authorizedQuantity: d.field.authorizedQuantity,
                                    materialId: d.field.materialId,
                                    userId: value.id,
                                    enterpriseId: value.companyInfoId,
                                    deptId: value.departmentId,
                                    positionId: value.roles.length > 0 ? value.roles[0].id : '',
                                    jobNumber: value.username,
                                    phone: value.phone,
                                    isDeleted: d.field.isDeleted == 'on' ? true : false,
                                    remark: d.field.remark,
                                    authorityManageId: data.id,
                                    userName: value.nickname,
                                    positionName: value.roles.length > 0 ? value.roles[0].name : '',
                                    deptName: value.departmentName,
                                    enterpriseName: value.companyInfoName
                                }
                                pushDataList.push(obj)
                            });

                            admin.req('enterprisecab/cabinet/admin/authorityMember/addBatch', JSON.stringify(pushDataList), function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    table.reload('memberFormTable');
                                    layer.close(addPermissionGroupMembersPopUp);
                                    table.reload('mainCabinetAuthorityTable');
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'POST', true, 'application/json; charset=utf-8');
                            return false
                        });


                        let userIdBox = xmSelect.render({
                            el: '#userIdBox',
                            filterable: true,
                            autoRow: true,
                            layVerify: 'required',
                            template({item, sels, name, value}) {
                                let roles = item.roles[0] ? item.roles[0].name : "";
                                return "<span class='colorBlack'>" + item.nickname + "</span><span style='font-weight: 600'>工号:</span>" +
                                    "<span class='colorBlack1'>" + item.username + "</span><span style='font-weight: 600'>电话:</span>" +
                                    "<span class='colorBlack1'>" + item.phone + "</span><span style='font-weight: 600'>岗位:</span>" +
                                    "<span class='colorBlack1'>" + roles + "</span><span style='font-weight: 600'>部门:</span>" +
                                    "<span class='colorBlack1'>" + item.departmentName + "</span><span style='font-weight: 600'>企业:</span>" +
                                    "<span class='colorBlack1'>" + item.companyInfoName + "</span>";
                            },
                            filterMethod: function (val, item, index, prop) {
                                let roles = item.roles[0] ? item.roles[0].name : "";
                                if (roles.toLowerCase().indexOf(val.toLowerCase()) != -1) {//把value相同的搜索出来
                                    return true;
                                }
                                if (item.username.toLowerCase().indexOf(val.toLowerCase()) != -1) {//把value相同的搜索出来
                                    return true;
                                }

                                if (item.nickname.toLowerCase().indexOf(val.toLowerCase()) != -1) {//名称中包含的搜索出来
                                    return true;
                                }
                                return false;//不知道的就不管了
                            },
                            prop: {
                                name: 'nickname',
                                value: 'id',
                            },
                            data: [],
                            on: function (data) {
                                if (data.isAdd) {
                                    admin.req('enterprisecab/cabinet/admin/authorityMember/getAuthorityMemberByUserId', {
                                        id: data.change[0].id,
                                        'cabinetId': thatData.cabinetId
                                    }, res => {
                                        if (res.code === 200) {
                                            formDataList.set(data.change[0].id, data.change[0])
                                            $('input[name="enterpriseId"]')
                                        } else {
                                            let index = data.arr.findIndex(item => item.id === data.change[0].id);
                                            if (index != -1) {
                                                data.arr.splice(index, 1);
                                            }
                                            layer.msg(res.msg, {icon: 2});
                                        }
                                    })
                                } else {
                                    formDataList.delete(data.change[0].id)
                                }
                            }
                        });

                        admin.req('user/admin/user/list', {limit: '99999'}, res => {
                            if (res.code === 200) {
                                userIdBox.update({data: res.data});
                            } else {
                                userIdBox.update({data: [],})
                            }
                        })

                    }
                    let smlSelectInstansExt = xmSelect.render({
                        el: '#materialId1',
                        model: {label: {type: 'text'}},
                        clickClose: true,
                        filterable: true,
                        disabled: true,
                        tree: {
                            show: true,
                            strict: false,
                            expandedKeys: [-1],
                        },
                        tips: '顶级分类',
                        prop: {
                            name: 'name',
                            value: 'id',
                            children: 'children'
                        },
                        data() {
                            //填充数据
                            return arr2treeExt;
                        },
                        on: function (data) {
                            let id = '';
                            for (var j = 0; j < data.arr.length; j++) {
                                if (j == 0) {
                                    id = data.arr[j].id
                                } else {
                                    id += ',' + data.arr[j].id;
                                }
                            }
                            $("form[lay-filter='addPermissionGroupMembersForm'] input[name='materialId']").val(id)
                        }
                    });
                    form.render("select");
                    form.render("checkbox");
                }
            })
        }


        /*渲染下拉框*/
        function loadSelectHtmlNew(data, tips, htmltarget, formName, type) {
            let html = '';
            if (tips) {
                html = '<option value>' + tips + '</option>'
            }
            if (!data || data == null) {
                $("form" + formName + " select[name='" + htmltarget + "']").html(html);
                form.render('select');
                return;
            }

            for (let i = 0; i < data.length; i++) {
                if (type == 1) {
                    html += `<option value='${data[i].id}'>${data[i].name}</option>`;
                } else if (type == 2) {
                    html += `<option value='${data[i].id}'>${data[i].nickname}</option>`;
                } else if (type == 3) {
                    html += `<option value='${data[i].value}'>${data[i].name}</option>`;
                } else if (type == 4) {
                    html += `<option value='${data[i].cabCode}'>${data[i].cabCode}</option>`;
                } else if (type == 5) {
                    html += `<option value='${data[i].id}'>${data[i].roomName}</option>`;
                } else if (type == 6) {
                    html += `<option value='${data[i].code}'>${data[i].code}</option>`;
                } else if (type == 7) {
                    html += `<option value='${data[i].id}' data='${JSON.stringify(data[i])}'>${data[i].nickname + "（" + data[i].phone + "）"}</option>`;
                }

            }
            $(formName + " select[name='" + htmltarget + "']").html(html);
            form.render('select');
        }
    });
</script>